package main

import (
	"flag"
	"fmt"

	"gitee.com/dark.H/gs"
)

func IfProxyStart() bool {
	// return !gs.Str(`networksetup -getwebproxy "Wi-Fi"`).Exec().In("Enabled: No")
	return gs.Str("networksetup -getsocksfirewallproxy wi-fi").Exec().In("Enabled: Yes")
}

func StopProxy() {
	gs.Str("networksetup -setsocksfirewallproxystate wi-fi off").Exec()
	// gs.Str(`networksetup -setwebproxystate "Wi-Fi" off`).Exec()
	// gs.Str(`networksetup -setsecurewebproxy "Wi-Fi" `).F(i + 1).Exec(
	// gs.Str(`networksetup -setsecurewebproxystate "Wi-Fi" off`).Exec()
}

func ProxySet(i int) {
	gs.Str("networksetup -setsocksfirewallproxy wi-fi 127.0.0.1 %d").F(i).Exec()
	gs.Str("networksetup -setsocksfirewallproxystate wi-fi on").Exec()

	// gs.Str(`networksetup -setsecurewebproxy "Wi-Fi" 127.0.0.1 %d`).F(i + 1).Exec()
	// gs.Str(`networksetup -setsecurewebproxystate "Wi-Fi" on`).Exec()

	// gs.Str(`networksetup -setwebproxy "Wi-Fi" 127.0.0.1 %d`).F(i + 1).Exec()
	// gs.Str(`networksetup -setwebproxystate "Wi-Fi" on`).Exec()
}

func main() {
	pp := 1
	start := false
	flag.IntVar(&pp, "p", 1080, "set socks5 port")
	flag.BoolVar(&start, "S", false, "to start proxy")
	flag.Parse()
	if start {
		fmt.Println("Start proxy")
		if IfProxyStart() {

		} else {
			ProxySet(pp)
		}

	} else {
		fmt.Println("Stop proxy")
		StopProxy()
	}
}
